package progress.exa33;

import java.io.*;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.util.Scanner;

public class ScannerStudy {

    public static void main(String[] args) throws IOException {
        //scannerInputStream();
        //scannerFile();
//        scannerPath();
        //scannerString();
        scannerChannel();
    }

    /**
     * Scanner输入流构造器学习
     */
    public static void scannerInputStream(){
        Scanner sc = new Scanner(System.in);
        int i = sc.nextInt();
        System.out.println("你输入了:"+ i);
    }

    /**
     * 对File文件扫描
     * @throws FileNotFoundException
     */
    public static void scannerFile() throws FileNotFoundException {
        //这里的路径就是文件的路径，可以用相对路径也可以用绝对路径
        File test = new File("麻子.txt");
        //这样in中存储的的就是麻子.txt文本的数据了
        Scanner in = new Scanner(test);
        //我们可以调用下面方法来对它进行操作
        while (in.hasNext()){
            String word = in.next();
            System.out.print(word);
        }
    }

    public static void scannerPath() throws IOException {
        Path path = FileSystems.getDefault().getPath("麻子.txt");
        Scanner in = new Scanner(path);
        //我们可以调用下面方法来对它进行操作
        while (in.hasNext()){
            String word = in.next();
            System.out.print(word);
        }
        //BufferedReader reader = Files.newBufferedReader(path);
    }

    public static void scannerString(){
        Scanner in = new Scanner("we should working hard");
        //我们可以调用下面方法来对它进行操作
        while (in.hasNext()){
            String word = in.next();
            System.out.println(word);
        }
    }

    public static void scannerChannel() throws FileNotFoundException {
        File file = new File("麻子.txt");
        FileInputStream fileInputStream = new FileInputStream(file);
        Scanner in = new Scanner(fileInputStream.getChannel());
        while (in.hasNext()){
            String word = in.next();
            System.out.print(word);
        }
    }



}
